package com.antaohua.platfrom.framework.container;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

public class ThreeColumn<K,C,V> {

	private List<ThreeEntry<K,C,V>> list = Lists.newArrayList();
	
	
	public int size() {
		
		return list.size();
	}

	
	public boolean isEmpty() {
		if(list.size()==0) {
			return true;
		}else {
			return false;
		}
	}


	public boolean containsKey(K key) {
		for (ThreeEntry<K, C, V> entry : list) {
			if(key!=null){
				if(key.equals(entry.getKey())) {
					return true;
				}
			}else {
				if(entry.getKey()==null) {
					return true;
				}
			}
		}
		return false;
	}


	public boolean containsValue(V value) {
		for (ThreeEntry<K, C, V> entry : list) {
			if(value!=null){
				if(value.equals(entry.getValue())) {
					return true;
				}
			}else {
				if(entry.getValue()==null) {
					return true;
				}
			}
		}
		return false;
	}


	public ThreeEntry<K,C,V> get(Object key) {
		for (ThreeEntry<K, C, V> entry : list) {
			if(key!=null){
				if(key.equals(entry.getKey())) {
					return entry;
				}
			}else {
				if(entry.getKey()==null) {
					return entry;
				}
			}
		}
		return null;
	}

	
	public ThreeEntry<K,C,V> put(K key,C character, V value) {
		for (int i=0;i<list.size();i++) {
			if(key!=null){
				if(key.equals(list.get(i).getKey())) {
					list.remove(i);
				}
			}else {
				if(list.get(i).getKey()==null) {
					list.remove(i);
				}
			}
		}
		ThreeEntry<K, C, V> entry = new ThreeEntry<K, C, V>(key, character, value);
		list.add(entry);
		return entry;
	}

	
	public ThreeEntry<K, C, V> remove(Object key) {
		ThreeEntry<K, C, V> entry = null;
		for (int i=0;i<list.size();i++) {
			if(key!=null){
				if(key.equals(list.get(i).getKey())) {
					entry = list.get(i);
					list.remove(i);
				}
			}else {
				if(list.get(i).getKey()==null) {
					entry = list.get(i);
					list.remove(i);
				}
			}
		}
		return entry;
	}


	public void clear() {
		list.clear();
	}

	
	public Set<K> keySet() {
		HashSet<K> result= Sets.newHashSet();
		for (ThreeEntry<K, C, V> entry : list) {
			result.add(entry.getKey());
		}
		return result;
	}

	
	public Collection<V> values() {
		List<V> result = Lists.newArrayList();
		for (ThreeEntry<K, C, V> entry : list) {
			result.add(entry.getValue());
		}
		return result;
	}

	
	public Set<ThreeEntry<K,C,V>> entrySet() {
		HashSet<ThreeEntry<K,C,V>> result= Sets.newHashSet();
		for (ThreeEntry<K, C, V> entry : list) {
			result.add(entry);
		}
		return result;
	}

	

}


